<template>
    <el-form :inline="true" :model="search" class="demo-form-inline">
        <el-form-item label="名称">
            <el-input v-model="search.nickName" />
        </el-form-item>
        <el-form-item label="手机号">
            <el-input v-model="search.phone" />
        </el-form-item>
        <el-form-item label="状态">
            <el-input v-model="search.status" />
        </el-form-item>
        <el-form-item label="会员身份">
          <el-select
           v-model="search.vip"
           style="width: 180px"
          >
            <el-option
              v-for="item in vips"
              :key="item.id"
              :label="item.vip"
              :value="item.id"
          />
          </el-select>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="getStaffList">查询</el-button>
        </el-form-item>
    </el-form>

    <div class="add-div">
        <el-button type="primary" plain @click="add">新增</el-button>
    </div>
    <!-- table -->
    <el-table :data="userInfoList" style="width: 80%">
        <el-table-column prop="nickName" label="名称" width="100" />
        <el-table-column prop="phone" label="手机号" width="120" />
        <el-table-column prop="email" label="邮件地址" width="160" />
        <el-table-column prop="authentication" label="认证状态" width="80" :formatter="authenticationFormatter"/>
        <el-table-column prop="balance" label="余额" width="80" />
        <el-table-column prop="point" label="积分" width="80" />
        <el-table-column prop="inviteCode" label="邀请码" width="160" />
        <el-table-column prop="status" label="状态" width="80" :formatter="statusFormatter"/>
        <el-table-column prop="createTimeStr" label="注册时间" width="200" />
        <el-table-column fixed="right" label="操作" width="180">
            <template #default="{ row }">
                <el-button link type="primary" size="small" @click="Edit(row)">修改</el-button>
                <el-button link type="primary" size="small" @click="Detail(row)">详情</el-button>
            </template>
        </el-table-column>
    </el-table>
    <div v-show="showPagination">
      <el-pagination :page-size="10" :pager-count="totalPage" layout="prev, pager, next" :total="totalCount" @current-change="handlePageChange"/>
    </div>
    <!-- dialog -->
    <el-dialog width="30%" :modal="staffInfo" v-model="dialogDetailVisible">
        <el-form ref="formRef" label-width="100px">
            <el-form-item label="投资人">
                <el-input v-model="station.userName"></el-input>
            </el-form-item>
            <el-form-item label="站点名称">
                <el-input v-model="station.stationName"></el-input>
            </el-form-item>
            <el-form-item label="地址">
                <el-input v-model="station.address"></el-input>
            </el-form-item>
            <el-form-item label="状态">
                <el-input v-model="station.status"></el-input>
            </el-form-item>
            <el-form-item label="创建时间">
                <el-input v-model="station.createTime"></el-input>
            </el-form-item>
            <el-form-item>
                <!-- <el-button type="primary" @click="onSubmitDetail">提交</el-button> -->
                <el-button type="primary" @click="DetailClose">关闭</el-button>
                </el-form-item>
            </el-form>
    </el-dialog>
</template>
<script setup>
import { ref } from 'vue'
import { ElMessage,ElMessageBox } from 'element-plus'
import { UserInfoList } from '@/api/user/userinfo.js'
var showPagination = ref(false);
const totalCount = ref(0)
const totalPage = ref(0)
//定义一个数据模型
var station = ref({
    nickName: '',
    phone: '',
    email: '',
    authentication:'',
    balance:'',
    point:'',
    inviteCode:'',
    status: '',
    type:'',
    createTime: '',
    pageSize:20
});

var search=ref({
    nickName: '',
    phone: '',
    email: '',
    authentication:'',
    status: '',
    vip:'',
    type:1,
    pageSize:20
})

// 定义一个list用来接收后端返回的数据列表
var userInfoList = ref([]);
//定义一个标识---是否需要展示dialog
var dialogDetailVisible=ref(false);

GetUserInfoList();

function GetUserInfoList() {
    UserInfoList(search.value)
    .then(res => {
      console.info(res.data)
      if (res.data.code == 200000) { 
        // hide();
        console.info(res.data.data);
        userInfoList.value=res.data.data.data
        if (res.data.data.totalCount > 0) {
          showPagination = true;
          totalPage.value=res.data.data.totalPage;
          totalCount.value=res.data.data.totalCount;
        }
      } else {
        //错误提示框
        ElMessage({
          message: res.data.msg,
          type: 'warning'
        });
      }
    })
}

function handlePageChange(newPage){
  coupon.value.pageNum=newPage
  ListCoupon(coupon.value)
    .then(res => {
      if (res.data.code == 200000) { 
        hide();
        console.info(res.data.data)
        couponList.value=res.data.data.data
        if (res.data.data.totalCount > 0) {
          showPagination = true;
          totalPage.value=res.data.data.totalPage;
          totalCount.value=res.data.data.totalCount;
        }
      } else {
        //错误提示框
        ElMessage({
          message: res.data.msg,
          type: 'warning'
        });
      }
    })
}

function authenticationFormatter(row, column, cellValue){
    if(cellValue === 0){
        return "未认证";
    }else{
        return "已认证";
    }
}
function statusFormatter(row, column, cellValue){
    if(cellValue === 0){
        return "正常";
    }else{
        return "已注销";
    }
}

function vipFormatter(row, column, cellValue){
    if(cellValue === 0){
        return "普通";
    }else{
        return "VIP";
    }
}
// 详情

function Detail(data) {
    station.value={...data};
    dialogDetailVisible.value=true;
}
function DetailClose() {
    dialogDetailVisible.value=false;
}


function Edit() {
    dialogDetailVisible.value=true;
}
function Delete() {
    ElMessageBox.confirm(
        '是否确认删除',
        '提醒', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
    }
    ).then(() => {
        console.info("delete station");
    }).catch(() => {
        ElMessage({
            type: 'info',
            message: '删除取消'
        })
    })
}

</script>